﻿namespace PDTPublisher
{
    using Microsoft.Practices.EnterpriseLibrary.Data;
    using System;
    using System.Data.Common;

    public class Utility
    {
        private static Database database = DatabaseFactory.CreateDatabase();

        public static string GetCurrentPDTVersion()
        {
            DbCommand sqlStringCommand = database.GetSqlStringCommand("SELECT ParamValue FROM dbo.WhSystemConfiguration WHERE ParamName='PdtVersion'");
            return database.ExecuteScalar(sqlStringCommand).ToString();
        }

        public static bool UpgradePDTVersion(string newVersion)
        {
            DbCommand sqlStringCommand = database.GetSqlStringCommand(string.Format("UPDATE dbo.WhSystemConfiguration SET ParamValue='{0}',UpdateDate=GETDATE() WHERE ParamName='PdtVersion'", newVersion));
            return (database.ExecuteNonQuery(sqlStringCommand) > 0);
        }
    }
}

